<template>
	<div class="myQuillEditorfon">
		<!-- Quill 富文本编辑器 -->
		<QuillEditor ref="myQuillEditor" theme="bubble" :options="editorOption" contentType="html" />
	</div>
</template>

<script>
	import { ref, onMounted, watch } from 'vue'
	import { QuillEditor } from '@vueup/vue-quill'
	import hljs from 'highlight.js'
	import 'highlight.js/styles/androidstudio.css'

	export default {
		name: 'coresonly',
		props: ['content'],
		components: {
			QuillEditor,
		},
		data() {
			return {
				editorOption: {
					readOnly: true,
					modules: {
						toolbar: null,
						syntax: {
							highlight: text => {
								return hljs.highlightAuto(text).value
							},
						},
					},
				},
			}
		},
		methods: {
			async get() {
				// 显示文章
				if (this.content) {
					const quill = this.$refs.myQuillEditor.editor.__quill
					quill.setContents(this.content)
				} else {
					console.log('没有内容')
				}
			},
		},
		mounted() {
			this.$nextTick(() => {
				this.get()
			})
		},
		watch: {
			content(newMedium) {
				// 更新内容
				this.get()
			},
		},
	}
</script>
<style scoped>
	.myQuillEditorfon {
		color: #777;
	}
	:deep(.ql-container, .ql-snow) {
		width: 820px;
		font-size: 16px;
		border: 0px;
		cursor: default;
	}

	:deep(.ql-editor) {
		padding: 0;
		cursor: default;
	}
	/* 语法高亮 */
	:deep(.ql-bubble .ql-editor pre) {
		margin: 5px 0 5px;
		position: relative;
		overflow: hidden;
		width: 820px;
		display: block;
		padding: 30px 8px 2px;
		line-height: 20px;
		word-wrap: break-word;
		text-align: left;
		background: #21252b;
		/* box-shadow: 0 10px 30px 0 rgb(0 0 0 / 40%); */
	}

	/** 3个点 */

	:deep(.ql-bubble .ql-editor pre::before) {
		position: absolute;
		word-wrap: break-word;
		top: 10px;
		left: 15px;
		width: 12px;
		height: 12px;
		font-weight: 700;
		font-size: 12px;
		color: rgb(190, 185, 185);
		line-height: 20px;
		white-space: nowrap;
		text-indent: 750px;
		background-color: #fc625d;
		border-radius: 16px;
		box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
		content: '';
	}

	/* 允许操作 */
	:deep(.ql-syntax) {
		-moz-user-select: text;
		-webkit-user-select: text;
		-ms-user-select: text;
		-khtml-user-select: text;
		user-select: text;
		font-size: 13px;
		overflow: hidden;
		outline: none;
		/* 直接隐藏元素超出的部分 */
	}
	:deep(.ql-editor p img) {
		display: block;
		margin: 0 auto;
	}
	@media screen and (max-width: 860px) {
		:deep(.ql-container, .ql-snow) {
			width: 100%;
			font-size: 14px;
		}

		/* 语法高亮 */
		:deep(.ql-bubble .ql-editor pre) {
			margin: 0.05rem 0 0.05rem;
			width: 100%;
			padding: 0.3rem 0.08rem 0.02rem;
			line-height: 0.2rem;
			/* box-shadow: 0 10px 30px 0 rgb(0 0 0 / 40%); */
		}
	}
</style>
